package com.ruoyi.oauth.sso.service;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.oauth.domain.OauthClient;
import com.ruoyi.oauth.domain.OauthToken;
import com.ruoyi.oauth.sso.vo.OAuthCode;
import com.ruoyi.oauth.sso.vo.OAuthRequest;
import org.springframework.ui.Model;

import javax.servlet.http.HttpServletRequest;

public interface IOauthService {

    /**
     * 验证客户端是否有效
     * @param clientId
     * @param clientSecret
     * @return
     */
    public OauthClient checkClient(String clientId, String clientSecret);


    /**
     * 验证客户端是否存在
     * @param model
     * @param clientId
     * @return
     */
    public OauthClient checkClient(Model model, String clientId);

    /**
     * 生成临时验证码
     * @param request
     * @return
     */
    public OAuthCode buildCode(OAuthRequest request);

    /**
     *  code转换成token
     * @param request
     * @param tokenRequest
     * @return
     */
    public  OauthToken code2Token(HttpServletRequest request, OAuthRequest tokenRequest);

    /**
     *  直接用客户端ID和密钥生成token
     * @param request
     * @param tokenRequest
     * @return
     */
    public  OauthToken secret2Token(HttpServletRequest request, OAuthRequest tokenRequest);

    /**
     *  刷新令牌
     * @param request
     * @return
     */
    public  OauthToken refresh2Token(HttpServletRequest request);

    /**
     *  简单模式，账号密码直接生成token
     * @param request
     * @param tokenRequest
     * @return
     */
    public  OauthToken pwd2Token(HttpServletRequest request, OAuthRequest tokenRequest);

    /**
     * 生成令牌
     * @param client
     * @param user
     * @param accessToken
     * @param scope
     * @return
     */
    public OauthToken grantToken(OauthClient client, LoginUser user, String accessToken, String scope);

    /**
     * 校验令牌
     * @param request
     * @return
     */
    public OauthToken checkToken(HttpServletRequest request);


    /**
     * 生成登录页面参数
     * @param model
     * @param request
     * @return
     */
    public boolean getLogin(Model model, OAuthRequest request);

    /**
     * 记录日志
     * @param clientId
     * @param userName
     * @param api
     * @param ip
     * @param token
     * @param remark
     * @param state
     * @return
     */
    public int log(String clientId, String userName, String api, String ip, String token, String remark, String state);

}
